
cmake_minimum_required(VERSION 2.8)
project(gstcam)

message("**project** " ${PROJECT_NAME})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")	# -std=gnu++11 包含C++11特性

# Qt is used to thread sync
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})

# setup CUDA
find_package(CUDA)

set(
	CUDA_NVCC_FLAGS
	${CUDA_NVCC_FLAGS}; 
    -O3 
	-gencode arch=compute_53,code=sm_53
    -gencode arch=compute_62,code=sm_62
    -gencode arch=compute_30,code=sm_30
)

# set openGL
find_package(OpenGL)

find_package(OpenCV)


# set output path

set(PROJECT_OUTPUT_DIR ${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_PROCESSOR})
SET(PROJECT_INCLUDE_DIR ${PROJECT_OUTPUT_DIR}/include)

# mkdir directory
file(MAKE_DIRECTORY ${PROJECT_INCLUDE_DIR}) 
FILE(MAKE_DIRECTORY ${PROJECT_OUTPUT_DIR}/bin)
FILE(MAKE_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib)


message("-- system arch:  ${CMAKE_SYSTEM_PROCESSOR}")
message("-- output path:  ${PROJECT_OUTPUT_DIR} ")

## set the target path
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib)


#INCLUDE for c/C++ include
include_directories(${PROJECT_INCLUDE_DIR})
include_directories(
    /usr/include/gstreamer-1.0
    /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/gstreamer-1.0/include
    /usr/include/glib-2.0
    /usr/include/libxml2 /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/glib-2.0/include
    /usr/include/opencv2
)


## lib file list
 file(GLOB gstcam_source  lib/gstreamer/*cpp  lib/image/*cpp lib/cuda/*cpp lib/cuda/*cu  lib/opengl/*cpp  )
 file(GLOB gstcam_include lib/gstreamer/*h  lib/image/*h lib/cuda/*h lib/opengl/*h)


 foreach(sources ${gstcam_source})
 MESSAGE("-- the ${PROJECT_NAME}  contion ${sources}")     
 endforeach(sources ${})
 
 
## creat gstcam shared library
cuda_add_library(${PROJECT_NAME} SHARED ${gstcam_source})
target_link_libraries(${PROJECT_NAME}    Qt4::QtGui GL GLEW gstreamer-1.0 gstapp-1.0 ${OpenCV_LIBS})

# transfer all headers to the include directory
foreach(include ${gstcam_include})
	message("-- Copying ${include}")
	configure_file(${include} ${PROJECT_INCLUDE_DIR} COPYONLY)
endforeach()

add_executable(gst_app_test src/gst-camera.cpp)
target_link_libraries(gst_app_test ${PROJECT_NAME})


 ##foreach(test ${OpenCV_LIBS})
 ##message("--- opencblibs " ${test})    
 ##endforeach(test ${OpenCV_LIBS})


add_executable(gst_appsrc_test src/gst-appsrc-test.cpp)
target_link_libraries(gst_appsrc_test ${OpenCV_LIBS} ${PROJECT_NAME} glib-2.0)  

add_executable(appsrc-rtp src/appsrc-rtp.cpp)
target_link_libraries(appsrc-rtp ${OpenCV_LIBS} ${PROJECT_NAME})  